/**
* Created by yyr on 2018/1/10
*已设立基金》头部详情
*/
<template>
    <div>
        <div v-if="!isHeadEdit" class="ca-box ca-p-20">
            <el-row>
                <el-col class="ca-align-right">
                    <el-button type="text"   @click="fundEdit()" class="ca-edit-btn el-icon-edit" :disabled="!isAuthBasicEdit">编辑</el-button>
                </el-col>
            </el-row>
            <div >
                <el-row>
                    <el-col :span="6" class="ca-border-r ca-m-r-20" style="text-align: center;">
                        <h3 class="ca-title-fullname">{{fund.fundFullname}}</h3>
                        <h4 class="ca-title-name">({{fund.fundName}})</h4>
                        <div class="ca-m-t-5">
                            <span :class="{quit:fund.fundState === 1,expire:fund.fundState !== 1}">投资中</span>
                            <span :class="{quit:fund.fundState === 3,expire:fund.fundState !== 3}">已到期</span>
                        </div>
                        <div class="ca-m-t-5">
                            <el-button type="text"  class="ca-p-8" :disabled='isChange'  @click="toPreFund(fundAnsatEstList[0].ansatId)">设立前基金</el-button>
                            <el-button type="text"  class="ca-p-8"  @click="toExpiredFund" v-if="isInvested" :disabled="!isAuthChangeExpired">一键转已到期基金</el-button>
                            <el-button type="text"  class="ca-p-8"  @click="toInvestedFund" v-if="!isInvested" disabled>一键转已设立基金</el-button>
                        </div>
                    </el-col>
                    <el-col :span="16">
                        <el-row class="ca-leng-28 ca-head-font">
                            <el-row>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">基金规模（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{fund.fundScale | format1}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">实缴规模（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{paid | format1}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">基金类型：</span>
                                    <span class="ca-color__money ca-font-size-14">{{fund.fundType | getNameById('fundType')}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">存续期：</span>
                                    <span class="ca-color__money ca-font-size-14">{{fund.investmentPeriod}}+{{fund.exitPeriod}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">已投项目：</span>
                                    <span class="ca-font-size-14">{{projects}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">已投金额（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{money | format1}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">投资余额（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{balance | format1}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">退出项目：</span>
                                    <span class="ca-font-size-14 ca-color__money">{{exitProjects}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">已分配（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{distribution | format1}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">基金支出（万）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{expenditure | format1}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">基金经理：</span>
                                    <span class="ca-font-size-14">{{fundUser}}</span>
                                </el-col>
                                <el-col :span="8">
                                    <span class="ca-font-color-gray ca-font-size-14">成立时间：</span>
                                    <span class="ca-font-size-14">{{$moment(fund.establishTime).format('YYYY-MM-DD')}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <span class="ca-font-color-gray ca-font-size-14">投资方向：</span>
                                <span class="ca-font-size-14 ca-m-l-10" v-for="i in industryList" :key="i.id">
                                        {{i.industry | getNameById('industry')}}
                                    </span>
                            </el-row>
                            <el-row>
                                <span class="ca-font-color-gray ca-font-size-14">基金团队成员：</span>
                                <span class="ca-font-size-14 ca-m-r-10" v-for="(item,index) in fundTeam" :key="index">
                                        {{item}}
                                    </span>
                            </el-row>
                        </el-row>
                    </el-col>
                </el-row>
            </div>
        </div>
        <fundHeadEdit v-if="isHeadEdit" @isEdit="isEdit" @addRedDot="addRedDot"></fundHeadEdit>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                isAuthBasicEdit: isNoAuth('已设立基金-基金详情-编辑'),
                isAuthChangeExpired: isNoAuth('已设立基金-基金详情-一键转已到期'),
                itemId: this.$route.params.fundId,
                isHeadEdit: false,
                fund: {},//基金信息
                balance: '',
                distribution: '',
                exitProjects: '',
                expenditure: '',
                fundAnsatEstList: [],
                industryList: [],
                money: '',
                paid: '',
                projects: '',
                fundUser: '',//基金经理
                fundTeam: [],//基金团队
                isChange: true,
                isInvested: false,
            }
        },
        created() {
            this.getHeadDetail();
        },
        props: {
        },
        watch: {
        },
        methods: {
            //获取头部详情信息
            getHeadDetail() {
                apiHttp(api.HEAD_DETAIL,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fund = ret.data.fund;
                        this.balance = ret.data.balance;//基金余额
                        this.distribution = ret.data.distribution;//已分配
                        this.exitProjects = ret.data.exitProjects;//退出项目
                        this.expenditure = ret.data.expenditure;//基金支出
                        this.fundAnsatEstList = ret.data.fundAnsatEstList;//投前基金信息
                        this.fundUserList = ret.data.fundUserList;//基金经理
                        this.industryList = ret.data.industryList;//投资方向
                        this.money = ret.data.money;
                        this.paid = ret.data.paid;
                        this.projects = ret.data.projects;
                        //显示基金经理
                        this.fundUserList.map(userManage=>{
                            if (userManage.userType === '1') {
                                this.fundUser = userManage.userName;
                            }
                        })
                        //显示基金管理团队
                        this.fundTeam = this.fundUserList.map(userTeam=>{
                            if (userTeam.userType === '2') {
                                return userTeam.userName;
                            }
                        })
                        if (this.fundAnsatEstList.length > 0) {
                            this.isChange = false;
                        }
                        if (this.fund.fundState === 3) {//已到期
                            this.isInvested = false;
                        } else {//已设立
                            this.isInvested = true;
                        }
                    }
                })
            },
            //切换编辑/详情
            fundEdit() {
                this.isHeadEdit = true;
            },
            //跳转设立前基金
            toPreFund(id) {
                this.$router.push({name: 'establishing-funds', params: {itemId: id, tabIndex: 0, openWindow: true}})
            },
            //转已到期
            toExpiredFund() {
                let query = {
                    fund: this.fund,
                    fundAnsatEstList: this.fundAnsatEstList,
                    industryList: this.industryList,
                    fundUserList: this.fundUserList
                }
                query.fund.fundState = 3;
                this.$confirm('是否转成已到期基金?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning',
                    showClose: false
                }).then(async () => {
                    apiHttp(api.HEAD_CHANGE, query).then(ret=> {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                type: 'success',
                                message: '操作成功!',
                                center: true
                            });
                            this.$router.push({name: 'expired-funds-list'})
                        }
                    });
                });
            },
            //转已设立
            toInvestedFund() {
                let query = {
                    fund: this.fund,
                    fundAnsatEstList: this.fundAnsatEstList,
                    industryList: this.industryList,
                    fundUserList: this.fundUserList
                }
                query.fund.fundState = 1;
                this.$confirm('是否转成已设立基金?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning',
                    showClose: false
                }).then(async () => {
                    apiHttp(api.HEAD_CHANGE, query).then(ret=> {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                type: 'success',
                                message: '操作成功!',
                                center: true
                            });
                            this.$router.push({name: 'investing-funds-list'})
                        }
                    });
                });
            },
            isEdit(val) {
                this.isHeadEdit = val;
                if (val === false) {
                    this.getHeadDetail();
                }
            },
            addRedDot() {
                this.$emit('addRedDot', 0)
            }
        },
        components: {
            'fundHeadEdit': require('./edit.vue'),//头部edit页
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .ca-title-fullname {
        font-size: 18px;
        line-height: 26px;
        color: #333;
    }
    .ca-title-name {
        font-size: 14px;
        line-height: 26px;
        color: #666;
        font-weight: normal;
    }
    .ca-align-right{
        font-size:20px;
    }
    .quit{
        width:51px;
        height:22px;
        background:#169bd5;
        display: inline-block;
        line-height:22px;
        color: #fff;
    }
    .expire{
        width:51px;
        height:22px;
        background:#999;
        display: inline-block;
        line-height:22px;
        color: #fff;
    }
    .ca-head-font .el-row{
        font-size:14px;
        color: #313131;
    }
</style>
